using System;
using System.Drawing;
using System.Collections;
using System.Data;
using System.IO;
using System.Diagnostics;
using ReportPrinting;

namespace LanAnh
{

    /// <summary>
	///  Creates a report with a table of birthdays
	/// </summary>
	public class SampleReportMaker1 : IReportMaker
	{
        private SamplePrintDialog1 myPrintDialog;

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="myPrintDialog"></param>
        /// 
        public SampleReportMaker1(SamplePrintDialog1 myPrintDialog)
        {
            this.myPrintDialog = myPrintDialog;            
        }

        /// <summary>
        /// The function to make a report
        /// </summary>
        /// <param name="reportDocument"></param>
        /// 
        public DataTable dtP;
        public void MakeDocument(ReportDocument reportDocument)
        {
            TextStyle.ResetStyles();

            // Setup the global TextStyles
            TextStyle.Heading1.FontFamily = new FontFamily("Comic Sans MS");
            TextStyle.Heading1.Brush = Brushes.DarkBlue;
            TextStyle.Heading1.SizeDelta = 5.0f;  
            TextStyle.TableHeader.Brush = Brushes.White;
            TextStyle.TableHeader.BackgroundBrush = Brushes.DarkBlue;
            TextStyle.TableRow.BackgroundBrush = Brushes.AntiqueWhite;
            TextStyle.Normal.Size = 12.0f;
            // Add some white-space to the page.  By adding a 1/10 inch margin
            // to the bottom of every line, quite a bit of white space will be added
            TextStyle.Normal.MarginBottom = 0.10f;
            TextStyle.TableHeader.MarginBottom = 0.05f;
            TextStyle.TableHeader.MarginTop = 0.05f;
            TextStyle.TableRow.MarginBottom = 0.05f;
            TextStyle.TableRow.MarginTop = 0.05f;

            // create a data table and a default view from it.
            DataView dv = GetDataView();
            // set the sort on the data view
            //if (myPrintDialog.cmbOrderBy.SelectedItem != null)
            //{
            //    string str = myPrintDialog.cmbOrderBy.SelectedItem.ToString();
            //    if (myPrintDialog.chkReverse.Checked)
            //    {
            //        str += " DESC";
            //    }
            //    dv.Sort = str;
            //}


            // create a builder to help with putting the table together.
            ReportBuilder builder = new ReportBuilder(reportDocument);

            // Add a simple page header and footer that is the same on all pages.
            builder.AddPageHeader("Birthdays Report", String.Empty, "page %p");
            builder.AddPageFooter(String.Empty, DateTime.Now.ToLongDateString(), String.Empty);

            builder.StartLinearLayout(Direction.Vertical);
            //builder.DefaultTablePen = reportDocument.ThinPen;

            // Add text sections
            builder.AddText("Birthdays", TextStyle.Heading1);
            builder.AddText("The following are various birthdays of people who "
                + "are considered important in history.");

            // Add a data section, then add columns
            builder.AddTable(dv, true);
            builder.Table.OuterPens = reportDocument.NormalPen;

            builder.AddColumn ("LastName", "Last Name", 1.5f, false, false);
            builder.AddColumn ("FirstName", "First Name", 1.5f, false, false);
            builder.AddColumn ("Birthdate", "Birthdate", 3.0f, false, false);
            // Set the format expression to this string.
            builder.CurrentColumn.FormatExpression = "D";

            builder.FinishLinearLayout();

        }


        public static DataView getView(DataTable dt)
        {
            return dt.DefaultView;
        }
        public static DataView GetDataView()
        {
            DataTable dt = new DataTable("People");

            dt.Columns.Add("FirstName", typeof(string));
            dt.Columns.Add("LastName", typeof(string));
            dt.Columns.Add("Birthdate", typeof(DateTime));
 
            dt.Rows.Add(new Object[] {"Theodore", "Roosevelt", new DateTime(1858, 11, 27)});
            dt.Rows.Add(new Object[] {"Winston ", "Churchill", new DateTime(1874, 11, 30)});
            dt.Rows.Add(new Object[] {"Pablo", "Picasso", new DateTime(1881, 10, 25)});
            dt.Rows.Add(new Object[] {"Charlie", "Chaplin", new DateTime(1889, 4, 16)});
            dt.Rows.Add(new Object[] {"Steven", "Spielberg", new DateTime(1946, 12, 18)});
            dt.Rows.Add(new Object[] {"Bart", "Simpson", new DateTime(1987, 4, 19)});
            dt.Rows.Add(new Object[] {"Louis", "Armstrong", new DateTime(1901, 8, 4)});
            dt.Rows.Add(new Object[] {"Igor", "Stravinski", new DateTime(1882, 6, 17)});
            dt.Rows.Add(new Object[] {"Bill", "Gates", new DateTime(1955, 10, 28)});
            dt.Rows.Add(new Object[] {"Albert", "Einstein", new DateTime(1879, 3, 14)});
            dt.Rows.Add(new Object[] {"Marilyn", "Monroe", new DateTime(1927, 6, 1)});
            dt.Rows.Add(new Object[] {"Mother", "Teresa", new DateTime(1910, 8, 27)});

            DataView dv = dt.DefaultView;

            return dv;

        }

	} // class
}
